<template>
  <view class="page">
    <view class="nav">
      <t-button variant="text" shape="square" @tap="goBack">
        <t-icon name="chevron-left" size="22" />
      </t-button>
      <text class="title">去水印历史</text>
    </view>
    <view class="list">
      <view class="item" v-for="(h, i) in history" :key="i">
        <view class="item-left">
          <t-icon name="magic" size="28" />
          <view class="meta">
            <text class="name">{{ h.name }}</text>
            <text class="sub">{{ formatDate(h.time) }}</text>
          </view>
        </view>
        <view class="item-actions">
          <t-button size="small" theme="primary" @tap="toDownloads">下载</t-button>
        </view>
      </view>
      <view v-if="history.length === 0" class="empty">暂无记录</view>
    </view>
  </view>
</template>

<script>
export default {
  data() { return { history: [] } },
  onShow() { this.history = uni.getStorageSync('wm_history') || [] },
  methods: {
    /** 返回上一页 */
    goBack() { uni.navigateBack() },
    /** 跳转到“我的下载” */
    toDownloads() { uni.navigateTo({ url: '/pages/downloads/index' }) },
    /** 格式化日期 */
    formatDate(ts) { const d = new Date(ts || Date.now()); const pad=(n)=>String(n).padStart(2,'0'); return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}` },
  }
}
</script>

<style>
.page { padding: 24rpx; }
.nav { display: flex; align-items: center; gap: 12rpx; }
.title { font-size: 32rpx; font-weight: 600; }
.list { margin-top: 24rpx; }
.item { background: #fff; border-radius: 20rpx; padding: 24rpx; display: flex; align-items: center; justify-content: space-between; margin-bottom: 16rpx; }
.item-left { display: flex; gap: 16rpx; align-items: center; }
.meta { display: flex; flex-direction: column; }
.name { font-size: 28rpx; font-weight: 600; }
.sub { color: #8c8c8c; font-size: 24rpx; }
.empty { color: #8c8c8c; text-align: center; padding: 40rpx 0; }
</style>
